/*
 * 关于别名的问题: 在import中输入@, 编辑器会根据alias和paths配置查找对应目录并提供键入提示
 *               但动态导入时, 如() => {'@/..'}, 编辑器无法通过上下文进行键入提示, 可以
 *               通过import('@/..')使用
 * */
import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    name: 'Home',
    component: () => import('@/pages/home/HomePage.vue'),
  },
  {
    path: '/song/:id',
    name: 'Song',
    component: () => import('@/pages/song/SongPage.vue'),
  },
  {
    path: '/Artists',
    name: 'Artists',
    component: () => import('@/pages/artist/ArtistsPage.vue'),
  },
  {
    path: '/Rank',
    name: 'Rank',
    component: () => import('@/pages/rank/RankPage.vue'),
  },
  {
    path: '/UserSongs',
    name: 'UserSongs',
    component: () => import('@/pages/mysongs/UserSongs.vue'),
    children: [
      {
        path: '',
        name: 'Favorites',
        component: () => import('@/pages/mysongs/components/FavoritesPage.vue'),
      },
      {
        path: '/UserSongs/Subscribe',
        name: 'Subscribe',
        component: () => import('@/pages/mysongs/components/SubscribePage.vue'),
      },
      {
        path: '/UserSongs/Personal',
        name: 'Personal',
        component: () => import('@/pages/mysongs/components/PersonalPage.vue'),
      },
      {
        path: '/UserSongs/Deal',
        name: 'Deal',
        component: () => import('@/pages/mysongs/components/DealPage.vue'),
      },
      {
        path: '/UserSongs/History',
        name: 'History',
        component: () => import('@/pages/mysongs/components/HistoryPage.vue'),
      },
      {
        path: '/UserSongs/Message',
        name: 'Message',
        component: () => import('@/pages/mysongs/components/MessagePage.vue'),
      },
    ],
  },
]

const router = createRouter({
  history: createWebHistory(),
  routes,
})

router.beforeEach(to => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
})

export default router
